<?php
	include_once("check_login.php");
	include_once("uitilities.php");
	include_once("../Business/user_service.php");
	
	$errormsg = '';
	$errorstatus = 'display:none';

	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		if (get_session('userName')=='')
		{
			$userName = $_POST["username"];
			$userPassword = $_POST["password"];
			$u = user_service::get_user_name($userName); 
			
			if ($u != null && $u->password == $userPassword)
			{
				$url= get('url');
				if($url == '')
				{
					$url = 'index.php';
				}
				set_session('userName', $userName);
				redirect($url);
			}
			else
			{
				$errormsg = 'Login fail!';
				$errorstatus = '';
			}
			
		}
	}

	
	$content = '
<div id="content" class="fullwidth">
	<div id="eventmsg" style="'.$errorstatus.'" class="error">
		<p>'.$errormsg.'</p>
	</div>

	<div style="width:200px; margin:0 auto;">
		<h2 id="content-title">Login</h2>
		<form method="post">
			<p>
				<label>Username</label><input name="username" type="text">
			</p>
			<p>
				<label>Password</label><input name="password" type="password"></p>
			<p class="label-submit">
				<input value="Login" type="submit"></p>
		</form>
		<div class="clear" />
		</div>
	</div>
</div>
';
	$navbar  = '';
	$sidebar = '';
	
	include_once("masters/root.php");
?>